.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
    str_1 BYTE "Please input a decimal number(0~4294967295) : ",0
    str_2 BYTE "The hexdecimal number is : ",0
    buf BYTE 20 DUP(0)
    temp DWORD 0
    anw BYTE 8 DUP(30h)

.code
start:
    invoke StdOut, addr str_1
    invoke StdIn, addr buf,20
    mov eax,0h
    mov ecx,0h
    mov edx,0h 

dec2dw:
    mov dl,byte PTR [buf+ecx]
    CMP dl,0h
    JE ready
    SUB dl,30h
    mov ebx,eax
    SHL ebx,3
    SHL eax,1
    ADD eax,ebx
    ADD eax,edx
    INC ecx
    JMP dec2dw

ready:
    mov ecx,8h
    mov edx,0h
    mov temp,eax

dw2hex1:
    mov eax,temp
    AND eax,0fh
    CMP eax,9h
    JLE dw2hex2
    ADD eax,57h
    JMP dw2hex3

dw2hex2:
    ADD eax,30h

dw2hex3:
    mov [anw+ecx-1h],al
    DEC ecx
    INC edx
    SHR eax,4
    SHR temp,4
    CMP ecx,0h
    JE Print
    JMP dw2hex1

Print:
    invoke StdOut, addr str_2
    invoke StdOut,addr anw
    invoke ExitProcess,0

END start
    
    
    
